<?exit?>

<!--/**
 *      [品牌空间] (C)2001-2010 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: map.html.php 5671 2011-03-07 07:12:59Z xuhui $
 */-->

<div class="main layout" id="map">
	<div class="content">
		<h3>$lang['shopmap']</h3>
		<div>
			<input type="hidden" id="inputmap" value="">
			<input type="hidden" id="shopid" value="$shopid">
		</div>
		<div style="width: 978px; height: 600px;" class="main_map" id="mapObj">
		</div>
	</div>
</div>
<script src="http://ditu.google.cn/maps/api/js?sensor=false&language=zh-CN" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">

	var map;
	var marker;
	var infowindow;
	var draggable = {$draggable};
	var contentString = "<div style=\"text-align:center;\">{$contentString}</div>";
	var confirmString = "<div style=\"text-align:center;\">$lang['shopmap_markconfirmmsg']<br>$lang['shopmap_markagainmsg']<br><div><a id=\"correctOk\" onclick=\"nermarker();\" class=\"mapmark left\">$lang['shopmap_ok']</a><a id=\"correctCancel\" onclick=\"closewindow();\" class=\"mapmark right\">$lang['shopmap_cancel']</a></div></div>";

	function initialize() {

		var latlng;
		var op = "$op";
		var mapapimark = "$shop[mapapimark]";
		var local = "$_SC[local]";

		if(mapapimark) {
			var mapapimarkaction = true;
			latlng = new google.maps.LatLng{$shop['mapapimark']};
		} else {
			if(!local) {
				var defaultmapaction = true;
				latlng = new google.maps.LatLng{$defaultshopmap};
			} else {
				var geoaction = true;
			}
		}
		var myOptions = {
			zoom: 14,
			center: latlng,
			navigationControl: true,
			mapTypeControl: false,
			scaleControl: true,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		map = new google.maps.Map(document.getElementById("mapObj"), myOptions);
		if(mapapimarkaction || (defaultmapaction && (op == 'mark'))) {
			    marker = new google.maps.Marker({
				draggable: draggable,
				position: latlng,
				map: map,
				title: "{$shop['subject']}"
			});
		} else if(geoaction) {
			var geocoder = new google.maps.Geocoder();
			if(geocoder) {
				geocoder.geocode({'address': local}, function(results, status) {
					if(status == google.maps.GeocoderStatus.OK) {
						map.setCenter(results[0].geometry.location);
						if(op == 'mark') {
							    marker = new google.maps.Marker({
								draggable: draggable,
								map: map,
								title: "{$shop['subject']}",
								position: results[0].geometry.location
							});
							infowindow = new google.maps.InfoWindow();
							google.maps.event.addListener(marker, 'click', function() {
								infowindow.open(map, marker);
							});
							infowindow.setContent(contentString);
							infowindow.open(map, marker);
							google.maps.event.addListener(marker, "dragstart", function(event) {
								infowindow.close(map);
							});
							google.maps.event.addListener(marker, "dragend", function(event) {
								infowindow.setContent(confirmString);
								infowindow.open(map, marker);
								$("#correctOk").click(function() {
									$.get('store.php?action=map&op=mark&id=' + {$shopid} + '&inputmap=' + event.latLng, function(data) {
										infowindow.setContent(data);
										infowindow.open(map, marker);
									});
								});
								$("#correctCancel").click(function() {
									infowindow.close(map);
								});
							});
						}
					} else {
						alert("{$lang['shopmap_mark_error']}");
					}
				});
			}
		}
		infowindow = new google.maps.InfoWindow();
		google.maps.event.addListener(marker, 'click', function() {
			infowindow.open(map, marker);
		});
		infowindow.setContent(contentString);
		infowindow.open(map, marker);
		google.maps.event.addListener(marker, "dragstart", function(event) {
			infowindow.close(map);
		});
		google.maps.event.addListener(marker, "dragend", function(event) {
			infowindow.setContent(confirmString);
			infowindow.open(map, marker);
			$("#correctOk").click(function() {
				$.get('store.php?action=map&op=mark&id=' + {$shopid} + '&inputmap=' + event.latLng, function(data) {
					infowindow.setContent(data);
					infowindow.open(map, marker);
				});
			});
			$("#correctCancel").click(function() {
				infowindow.close(map);
			});
		});
	}
	function nermarker() {
	    var newlatLng = marker.getPosition();
        $.get('store.php?action=map&op=mark&id=' + {$shopid} + '&inputmap=' + newlatLng, function(data) {
            infowindow.setContent(data);
            infowindow.open(map, marker);
        });
	}
	function closewindow() {
        infowindow.close(map);
	}
	initialize();
</script>
